import {
    pageQueryInfo, getInfoType, logicDeleteInfoById, logicBatchDeleteInfoByIds,
     updateInfo,
 } from '@/api/admin/common'
import { message,messageType } from '@/utils/message';

const state = {
    infoRespData: [],
    infoTotal: 0,

    infoType: [],
    infoTypeTotal: 0,
};
const mutations = {

    // 分页查询建议反馈信息
    pageQueryInfoMutations(state, param) {
        state.infoRespData = param.data;
        state.infoTotal = param.total;
    },
    // 分页查询建议反馈信息
    queryInfoTypeMutations(state, param) {
        state.infoType = param.data;
        state.infoTypeTotal = param.total;
    },
};
const actions = {
    // 分页查询建议反馈信息
    async pageQueryInfoActions(context, page) {
        await pageQueryInfo(page).then(resp => {
            if (!resp) return;
            console.log("infoRespData-->", resp.data);
            context.commit('pageQueryInfoMutations', resp.data)
        }, error => {
            console.log(error);
        })
    },

    // 查询资讯类型
    async queryInfoTypeActions(context, page) {
        await getInfoType(page).then(resp => {
            if (!resp) return;
            console.log("getInfoType-->", resp.data);
            context.commit('queryInfoTypeMutations', resp.data)
        }, error => {
            console.log(error);
        })
    },

    // 逻辑删除资讯信息
    async logicDeleteInfoByIdActions(context, id) {
        await logicDeleteInfoById(id).then(resp => {
            if (!resp) return;
            console.log(resp);
        }, error => {
            console.log(error);
        })
    },

    // 批量逻辑删除资讯信息
    async logicBatchDeleteInfoByIdsActions(context, ids) {
        await logicBatchDeleteInfoByIds(ids).then(resp => {
            if (!resp) return;
            console.log(resp);
        }, error => {
            console.log(error);
        })
    },

    

    // 修改询资讯信息
    async updateInfoActions(context, form) {
        await updateInfo(form).then(resp => {
            if (!resp) return;
            console.log(resp);
            message(messageType().success, "操作数据成功");
        }, error => {
            console.log(error);
        })
    },
};

export default {
    namespaced: true,
    state,
    mutations,
    actions,
}